# cmake_minimum_required(VERSION 2.8.0)
# https://blog.csdn.net/lzz137/article/details/118526041
cmake_minimum_required(VERSION 3.6)
set(PROJECT_NAME TestLibDill)
set(MODULE_MAIN TestLibDill)

# 使能c++11
set(CMAKE_CXX_STANDARD 11)

# project(${PROJECT_NAME})


string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_lower)

if(cmake_build_type_lower STREQUAL "release")
    message(VERBOSE "begin build release")
    set(CMAKE_CXX_VISIBILITY_PRESET hidden)
    set(CMAKE_C_VISIBILITY_PRESET hidden)
else()
    message(VERBOSE "begin build debug")
    add_definitions(-DDEBUG)
endif()

set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_C_VISIBILITY_PRESET hidden)

# ADD_DEFINITIONS(-g -O0 -Wall -Wno-unused-but-set-variable)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++11 -D__linux__=1 -D__OS_LINUX__=1 -O2 -pthread -fopenmp -fPIC")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++11 -fexceptions -fPIC -frtti -Wall -Wno-literal-suffix")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -g -std=c++14 -fPIC -frtti -Wall -Wno-literal-suffix -D__linux__=1 -O -fPIC  -W -lpthread -ldl -ggdb")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g  -pthread -std=c99")

# -Wall选项意思是编译后显示所有警告。
# -W选项类似-Wall，会显示警告，但是只显示编译器认为会出现错误的警告
# add_definitions(-DOS_LINUX -D_OS_LINUX)
set(CMAKE_BUILD_TYPE "Release")

add_definitions(-DNDEBUG)
add_definitions(-DOS_LINUX)
add_definitions(-D__linux__)
add_definitions(-D_OS_DISK_MANAGER)
add_definitions(-DDILL_DISABLE_SOCKETS)
add_definitions(-DHAVE_EPOLL)
add_definitions(-DDILL_THREADS)
#add_definitions(-DENABLE_RECORD)
add_definitions(-DDILL_SOCKETS)
add_definitions(-DAIO_SOCKET)
add_definitions(-D__GLIBC__)

add_compile_options(-fno-stack-protector)
option(ENABLE_GB28181 "Enable gb28181" true)
option(ENABLE_RTC "Enable rtc" true)
option(ENABLE_RTSP "Enable rtsp" true)
option(ENABLE_OPENSSL "Enable OpenSSL" true)

include_directories("${CMAKE_SOURCE_DIR}/HILibDill/include")


include_directories(

    include
)

# 查找openssl是否安装
find_package(OpenSSL QUIET)

if(OPENSSL_FOUND AND ENABLE_OPENSSL)
    message(STATUS "found library:${OPENSSL_LIBRARIES},ENABLE_OPENSSL defined")
    include_directories(${OPENSSL_INCLUDE_DIR})
    add_definitions(-DENABLE_OPENSSL)
    list(APPEND LINK_LIB_LIST ${OPENSSL_LIBRARIES})

    if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND OPENSSL_USE_STATIC_LIBS)
        list(APPEND LINK_LIB_LIST dl)
    endif()

else()
    message(WARNING "openssl未找到，rtmp将不支持flash播放器，https/wss/rtsps/rtmps也将失效")
endif()

# 查找x264是否安装
find_package(X264 QUIET)

if(X264_FOUND AND ENABLE_X264)
    message(STATUS "found library:${X264_LIBRARIES},ENABLE_X264 defined")
    include_directories(${X264_INCLUDE_DIRS})
    add_definitions(-DENABLE_X264)
    list(APPEND LINK_LIB_LIST ${X264_LIBRARIES})
endif()

# file(GLOB SRC_LIST "*.c" "*.cpp")
set(LIBS utility math)
file(GLOB SRC_LIST
       TestLibDill.cpp

    # src/server-sig.cpp
    # src/server-talk.cpp
    # src/server-room.cpp
    #src/server-record.cpp

    # src/server-room-view.cpp
)

# file(GLOB SRC_SRT_LIST "source/srt/*.c" "source/srt/*.cpp")

# add link library，添加可执行文件所需要的库，比如我们用到了libm.so（命名规则：lib+name+.so），就添加该库的名称
# TARGET_LINK_LIBRARIES(${PROJECT_NAME} m)

# link_directories(${PROJECT_SOURCE_DIR}../lib/)
# add_executable(${PROJECT_NAME} ${SRC_LIST})
#LINK_DIRECTORIES("${PROJECT_BINARY_DIR}/lib" ../lib/linux/ffmpeg) # 添加lib目录为静态库目录

# link_directories(${PROJECT_BINARY_DIR})
# link_directories(${PROJECT_SOURCE_DIR}../lib/)
# link_directories(/usr/local/lib
# ${PROJECT_SOURCE_DIR}/../lib/linux/ffmpeg

# )HIAvcodeSDK HILibDB HILibDataAPI
set(LIBS HILibDill
    pthread  dl)
add_executable(${MODULE_MAIN} ${SRC_LIST}) # add_executable用于生成执行文件的地方
target_link_libraries(TestLibDill ${LIBS}) # 此举是将utility和math链接到main里面，然后在add_executable生成可执行文件test

